package com.fh.Thread_Protect;

//测试如何将一个线程设置成守护线程
public class Protection {
    public static void main(String[] args) throws InterruptedException {
        MyDeamonThread myDeamonThread = new MyDeamonThread();
        //将 myDeamonThread 设置为守护线程，当所有线程结束后，myDeamonThread 也就自动结束
        //如果没有设置，那么即使main线程执行完毕，myDeamonThread 也不退出
        myDeamonThread.setDaemon(true);
        myDeamonThread.start();
        for (int i = 0;i<100;i++){
            Thread.sleep(50);
            System.out.println("小明辛苦学习"+"-" +i);
        }
    }
}
class MyDeamonThread extends Thread {
    @Override
    public void run() {
        for (;;) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("小明在学习线程");
        }
    }
}
